<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <button class="btn1">发送了一个简单字符串(表单格式)</button>
    <br>
    <button class="btn2">发送了一个简单字符串(json格式)</button>
    <br>
    <button class="btn3">发送了一个user对象(表单格式)</button>
    <br>
    <button class="btn4">发送了一个user对象(json格式)</button>
    <br>
    <button class="btn5">发送了一个user对象(json格式) 后端用Map集合来收</button>
    <br>
    <button class="btn6">发送了一个user对象集合</button>
    <br>
    <button class="btn7">获取后端发过来的数据</button>
    <br>
</body>
<script src="js/jquery.min.js"></script>
<script >
    $(".btn1").click(function (){
        $.ajax({
            url:"json/getAString",
            method:"post",
            data:{
                msg:"hello world"
            },
            success:function(data){
                console.log(data);
            }
        })
    })

    $(".btn2").click(function (){
        $.ajax({
            url:"json/getAString2",
            method:"post",
            data:"nihao shijie",
            contentType:"application/json",
            success:function(data){
                console.log(data);
            }
        })
    })

    $(".btn3").click(function (){
        $.ajax({
            url:"json/getAUser",
            method:"post",
            data: {
                "userId":"1",
                "username":"zhangsan",
                "password":"123456",
                "sex":"mela",
                "birthday":"1995-5-5"
            },
            success:function(data){
                console.log(data);
            }
        })
    })

    $(".btn4").click(function (){
        $.ajax({
            url:"json/getAUser2",
            method:"post",
            data: JSON.stringify({
                "userId":"1",
                "username":"zhangsan",
                "password":"123456",
                "sex":"mela",
                "birthday":"1995-5-5"
            }),
            contentType: "application/json",
            success:function(data){
                console.log(data);
            }
        })
    })

    $(".btn5").click(function (){
        $.ajax({
            url:"json/getAMap",
            method:"post",
            data: `{
                "userId":"1",
                "username":"zhangsan",
                "password":"123456",
                "sex":"mela",
                "birthday":"1995-5-5"
            })`,
            contentType: "application/json",
            success:function(data){
                console.log(data);
            }
        })
    })

    $(".btn6").click(function (){
        $.ajax({
            url:"json/getAList",
            method:"post",
            data: JSON.stringify([
                {
                    "userId":"1",
                    "username":"zhangsan",
                    "password":"123456",
                    "sex":"mela",
                    "birthday":"1995-5-5"
                },
                {
                    "userId":"2",
                    "username":"lisi",
                    "password":"123456",
                    "sex":"femela",
                    "birthday":"1995-5-5"
                }
            ]),
            contentType: "application/json",
            success:function(data){
                console.log(data);
            }
        })
    })

    $(".btn7").click(function (){
        $.ajax({
            url:"json/backUsers",
            method:"post",
            dataType:"json",
            success:function(data){
                console.log(data.username);
                console.log(data.password);
                console.log(data.username);
                console.log(data.birthday);
            }
        })
    })
</script>
</html>